package model.core;

import java.io.IOException;

import view.GUITest;

import model.ability.HandlerFactory;
import model.area_effect.AreaEffectRemover;
import model.entity.Avatar;
import model.map.AvatarStateObserver;
import model.map.GameMap;
import model.map.GameStateObserver;
import model.map.MapPoint;
import model.map.ViewMap;

public class GameRunner{
	
	/**
	 * Called by the controller whenever the user begins a game.
	 * If it's a new game, set the appropriate avatar in NewGameInstantiator BEFORE CALLING THIS.
	 * @param instantiator either NewGameInstantiator or LoadGameInstantiator (depending upon user's selection)
	 */
	public static void runGame(Instantiator instantiator){
		FileParser parser = new FileParser("Data\\Instantiation.dat");
		GameInstantiation inst = new GameInstantiation();
		
		try {
			parser.parseAndInstantiate(inst);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		GameMap map = null;
		try {
			map = parser.createGameMap();
		} catch (IOException e) {
			e.printStackTrace();
		}
		//HERE: get Occupation preference
		instantiator.placeItems(map);
		
		GameScheduler.getInstance().startTimer();
		
		HandlerFactory handlerFactory = new HandlerFactory(map);
		AreaEffectRemover aeRemover = new AreaEffectRemover(map);
		
		Avatar avatar = instantiator.getAvatar();

		MapPoint max = map.getBoundary();
		int xDim = max.getXCoordinate();
		int yDim = max.getYCoordinate();
		ViewMap viewMap = new ViewMap(xDim, yDim, "grassTile", avatar);
		
		String shrouded = null;
		
		AvatarStateObserver avatarStateObserver = new AvatarStateObserver(avatar, map, shrouded);
		GameStateObserver gameStateObserver = new GameStateObserver(map, viewMap, avatar);
		
		GUITest.startGUI(viewMap);
		
		while(true){
			
		}
	}
	
}
